<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Priority_option_entity{
	var $current_dbprefix = "";
	var $id = 0;
	var $priority = 0;
	var $price = 0;
	var $priority_percentage = 0;
	
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function __destruct() {
		$ci= & get_instance();
		$ci->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setId($input){
		$this->id=$input;
	}
	function setPriority($input){
		$this->priority = $input;
	}
	function setPrice($input){
		$this->price = $input;
	}
	function setPriorityPercentage($input){
		$this->priority_percentage = $input;
	}
	
	function getId(){
		return $this->id;
	}
	function getPriority(){
		return $this->priority;
	}
	function getPrice(){
		return $this->price;
	}
	function getPriorityPercentage(){
		return $this->priority_percentage;
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		if($cmd == 'id'){
			$result = $ci->db->where('id',$input)->get(TBL_PRIORITY_OPTION)->result();
		}else if($cmd == 'priority'){
			$result = $ci->db->where('priority',$input)->get(TBL_PRIORITY_OPTION)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->priority = $result[0]->priority;
			$this->price = $result[0]->price;
			$this->priority_percentage = $result[0]->priority_percentage;
			return $this;
		}
		return false;
	}
	function getPriorityOptionList(){
		$ci=& get_instance();
		return $ci->db->get(TBL_PRIORITY_OPTION)->result();
	}
	function save($entity){
		$ci=& get_instance();
		$ci->db->set('priority',$entity->getPriority());
		$ci->db->set('price',$entity->getPrice());
		$ci->db->set('priority_percentage',$entity->getPriorityPercentage());
		$ci->db->insert(TBL_PRIORITY_OPTION);
		return $ci->db->insert_id();
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set('priority', $this->priority);
		$ci->db->set('price', $this->price);
		$ci->db->set('priority_percentage',$this->getPriorityPercentage());
		return $ci->db->where('id', $this->id)->update(TBL_PRIORITY_OPTION);
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->where('id',$id);
		$ci->db->delete(TBL_PRIORITY_OPTION);
	}
}